/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Classes;

import java.util.Calendar;
import java.util.Objects;

/**
 * Représente une personne
 * @author userinsta
 */
public class Personne {
    private String _nom = null ;
    private String _prenom = null;
    private int _dateDeNaissance;
    private String _numeroTelephone = null;
    private Adresse _adresse =null;
    /**
     * Constructors
     */
    public Personne(){}
    
    public Personne(String nom, String prenom, int dateDeNaissance, String numeroTelephone, Adresse adresse) throws Exception {
        this.setNom(nom);
        this.setPrenom(prenom);
        this.setDateDeNaissance(dateDeNaissance);
        this.setNumeroTelephone(numeroTelephone);
        this.setAdresse(adresse);
    }
    /**
     * Getters and Setters
     * @return 
     */
    public String getNom() {
        return _nom;
    }

    public String getPrenom() {
        return _prenom;
    }

    public int getDateDeNaissance() {
        return _dateDeNaissance;
    }
    
    public int getAge() throws Exception {
        int result = 0;

        // if the year of birth is incorrect..
        if (getDateDeNaissance() == -1)
        {
            throw new Exception("Age pas conforme");
        } else
        {
            int currentYear = Calendar.getInstance().get(Calendar.YEAR);

            result = currentYear - getDateDeNaissance();
        }
        return result;
    }
    public Adresse getAdresse() {
        return _adresse;
    }
    public String getNumeroTelephone() {
        return _numeroTelephone;
    }
    
     public void setNom(String nom) {
        this._nom = nom;
    }

    public void setPrenom(String prenom) {
        this._prenom = prenom;
    }

    public void setDateDeNaissance(int dateDeNaissance) throws Exception {
        int currentYear = Calendar.getInstance().get(Calendar.YEAR);
        // If the year of birth is incorrect..
        if ((dateDeNaissance > currentYear) || (dateDeNaissance < currentYear - 200))
        {
            throw new Exception("Année de naissance pas conforme");
        } else
        {
            this._dateDeNaissance = dateDeNaissance;
        }
    }

    public void setNumeroTelephone(String numeroTelephone) {
        this._numeroTelephone = numeroTelephone;
    }
    
    public void setAdresse(Adresse adresse) {
        this._adresse = adresse;
    }

    /**
     * Equals
     * @param obj
     * @return true si equals 
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Personne other = (Personne) obj;
        if (!Objects.equals(this._nom, other._nom)) {
            return false;
        }
        if (!Objects.equals(this._prenom, other._prenom)) {
            return false;
        }
        if (this._dateDeNaissance != other._dateDeNaissance) {
            return false;
        }
        if (!Objects.equals(this._numeroTelephone, other._numeroTelephone)) {
            return false;
        }
        if (!Objects.equals(this._adresse, other._adresse)) {
            return false;
        }
        return true;
    }
}
